<%@ page import="dao.CartsDAO" %>
<%@ page import="dao.ProductDAO" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    int cid = Integer.parseInt(request.getParameter("cid"));
    int newCount = Integer.parseInt(request.getParameter("count"));
    int oldCount = Integer.parseInt(request.getParameter("ocount"));
    int pid = Integer.parseInt(request.getParameter("pid"));

    CartsDAO cartsDAO = new CartsDAO();
    int result = cartsDAO.modifyCartsCount(newCount-oldCount,cid);
    // 更新成功
    if ( result > 0 ) {
        ProductDAO productDAO = new ProductDAO();
        int r = productDAO.modifyGoodsNumber(newCount-oldCount,pid);
        if ( r > 0 ) {
            response.sendRedirect("carts.jsp");
        } else {
            out.println("更新失败");
        }
    } else {
        out.println("更新失败！");
    }
%>